package com.white.loggerserver.room

import android.os.Parcel
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey

/**
 * Created by ytf on 2020/06/08.
 * Description:
 */
@Entity(tableName = MyRoomDb.recordTableName)
data class Record(
    @PrimaryKey(autoGenerate = true) var rid : Long,
    @ColumnInfo(defaultValue = "title") var title : String,
    @ColumnInfo(defaultValue = "desc") var desc : String,
    @ColumnInfo var addTime : Long,
    @ColumnInfo var size : Long,
    @ColumnInfo var path : String) : Parcelable {

    constructor(parcel: Parcel) : this(
        parcel.readLong(),
        parcel.readString(),
        parcel.readString(),
        parcel.readLong(),
        parcel.readLong(),
        parcel.readString()) {
    }

    constructor() : this(0, "title", "desc", 0, 0, "")

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeLong(rid)
        parcel.writeString(title)
        parcel.writeString(desc)
        parcel.writeLong(addTime)
        parcel.writeLong(size)
        parcel.writeString(path)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<Record> {
        override fun createFromParcel(parcel: Parcel): Record {
            return Record(parcel)
        }

        override fun newArray(size: Int): Array<Record?> {
            return arrayOfNulls(size)
        }
    }
}